package com.jxaummd.aquaculture.util.service;

import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.IBinder;

import com.jxaummd.aquaculture.util.listener.IGetMessageCallBack;

public class MyServiceConnection implements ServiceConnection {

    private MQTTService mqttService;
    private IGetMessageCallBack IGetMessageCallBack;



    @Override
    public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        //从Binder处获取Service
        mqttService = ((MQTTService.CustomBinder)iBinder).getService();
        //自定义Service中接收到mqtt消息的回调函数
        mqttService.setIGetMessageCallBack(IGetMessageCallBack);
    }

    @Override
    public void onServiceDisconnected(ComponentName componentName) {

    }

    public void sendMag(String topic, String msg) {
        mqttService.pubMsg(topic, msg);
    }

    public MQTTService getMqttService(){
        return mqttService;
    }

    public void setIGetMessageCallBack(IGetMessageCallBack IGetMessageCallBack){
        this.IGetMessageCallBack = IGetMessageCallBack;
    }
}